//
//  InAppPurchaseComboTopViewCollectionViewCell.swift
//  FrameProduct
//
//  Created by delegate on 2025/10/21.
//

import UIKit

class InAppPurchaseComboTopViewCollectionViewCell: UICollectionViewCell {
    var packageType: Int = 1
    var isHasActivity: Bool = false
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    private func setupUI() {
        contentView.addSubviews(contentImageView, tagButton)
        contentImageView.addSubviews(specificationLabel, priceLabel, activityLabel, activityTipLabel)
        contentImageView.snp.makeConstraints { make in
            make.left.equalToSuperview()
            make.right.equalToSuperview()
            make.bottom.equalToSuperview()
            make.top.equalTo(4)
        }
        tagButton.snp.makeConstraints { make in
            make.top.equalTo(contentImageView.snp.top).offset(-4)
            make.left.equalTo(contentImageView.snp.left).offset(-1)
            make.width.equalTo(46)
            make.height.equalTo(22)
        }
        specificationLabel.snp.makeConstraints { make in
            make.top.equalTo(27)
            make.left.right.equalToSuperview()
            make.height.equalTo(21)
        }
        priceLabel.snp.makeConstraints { make in
            make.top.equalTo(specificationLabel.snp.bottom).offset(0)
            make.left.right.equalToSuperview()
            make.height.equalTo(44)
        }
        activityLabel.snp.makeConstraints { make in
            make.top.equalTo(priceLabel.snp.bottom).offset(0)
            make.left.right.equalToSuperview()
            make.height.equalTo(18)
        }
        activityTipLabel.snp.makeConstraints { make in
            make.left.bottom.right.equalToSuperview()
            make.height.equalTo(27)
        }
    }
    func hasBgColor(isHave: Bool) {
        if isHave {
            
            specificationLabel.textColor = .lxs.hex("#30304B")
            priceLabel.textColor = .lxs.hex("#30304B")
            activityLabel.textColor = .lxs.hex("#30304B")
            activityTipLabel.textColor = .lxs.hex("#000000")
            
            switch packageType {
            case 1:
                activityTipLabel.backgroundColor = .lxs.hex("#9CCDFF")
                contentImageView.image = UIImage(named: "buy_vip_cell_bg_img")
            case 2:
                activityTipLabel.backgroundColor = .lxs.hex("#F3DA95")
                contentImageView.image = UIImage(named: "buy_svip_cell_bg_img")
            case 3:
                activityTipLabel.backgroundColor = .clear
                contentImageView.image = UIImage(named: "buy_personal_cell_bg_img")
            default:
                activityTipLabel.backgroundColor = .lxs.hex("#9CCDFF")
                contentImageView.image = UIImage(named: "buy_vip_cell_bg_img")
            }
        }else {
            
            contentImageView.image = UIImage(named: "")
            
            specificationLabel.textColor = .lxs.hex("#FFFFFF")
            priceLabel.textColor = .lxs.hex("#FFFFFF")
            
            activityLabel.textColor = .lxs.hex("#FFFFFF")
            activityTipLabel.textColor = .lxs.hex("#B7DBFF")
            
            activityTipLabel.backgroundColor = .clear
        }
    }
    //=================================================================
    //                            lazy
    //=================================================================
    // MARK: - lazy
    private lazy var contentImageView: UIImageView = {
        let imageView = UIImageView()
        imageView.layer.cornerRadius = 12
        imageView.layer.masksToBounds = true
        imageView.layer.borderColor = UIColor.lxs.hex("#415275").cgColor
        imageView.layer.borderWidth = 1
        return imageView
    }()
    private lazy var tagButton: UIButton = {
        let button = UIButton()
        button.setTitle("最划算", for: .normal)
        button.setTitle("最划算", for: .selected)
        button.setTitleColor(.lxs.hex("#FFFFFF"), for: .normal)
        button.setTitleColor(.lxs.hex("#FFFFFF"), for: .selected)
        button.titleLabel?.font = .lxs.font(size: 11)
        button.setBackgroundImage(UIImage(named: "buy_tag_bg_img"), for: .normal)
        button.setBackgroundImage(UIImage(named: "buy_tag_bg_img"), for: .selected)
        button.isUserInteractionEnabled = false
        return button
    }()
    private lazy var specificationLabel: UILabel = {
        let label = UILabel(frame: .zero)
        label.text = "普通年付"
        label.textColor = .lxs.hex("#30304B")
        label.font = .lxs.font(size: 14)
        label.textAlignment = .center
        return label
    }()
    private lazy var priceLabel: UILabel = {
        let label = UILabel(frame: .zero)
        let prefix = "￥"
        let suffix = "288"
        let attri = NSMutableAttributedString(string: "\(prefix)\(suffix)")
        attri.addAttributes([NSAttributedString.Key.foregroundColor : UIColor.lxs.hex("#30304B"), NSAttributedString.Key.font: UIFont.lxs.font(size: 12)], range: NSRange(location: 0, length: prefix.count))
        attri.addAttributes([NSAttributedString.Key.foregroundColor : UIColor.lxs.hex("#30304B"), NSAttributedString.Key.font: UIFont.lxs.font(size: 30)], range: NSRange(location: prefix.count, length: suffix.count))
        label.attributedText = attri
        label.textAlignment = .center
        return label
    }()
    private lazy var activityLabel: UILabel = {
        let label = UILabel(frame: .zero)
        label.text = "送10天"
        label.textColor = .lxs.hex("#FFFFFF")
        label.font = .lxs.font(size: 12)
        label.textAlignment = .center
        return label
    }()
    private lazy var activityTipLabel: UILabel = {
        let label = UILabel(frame: .zero)
        label.text = "¥20.3/月·比月卡省¥50"
        label.textColor = .lxs.hex("#000000")//#B7DBFF
        label.font = .lxs.font(size: 10)
        label.textAlignment = .center
        label.backgroundColor = .lxs.hex("#9CCDFF")
        label.layer.cornerRadius = 12
        label.layer.maskedCorners = [.layerMinXMaxYCorner, .layerMaxXMaxYCorner]
        label.layer.borderColor = UIColor.lxs.hex("#415275").cgColor
        label.layer.borderWidth = 1
        return label
    }()
}
extension InAppPurchaseComboTopViewCollectionViewCell: ReuseIdentifiable {
    static var reuseIdentifier: String {
        return String(describing: self)
    }
    
    
}
